package com.jackwoo.jerrymouse.util;

import com.jackwoo.jerrymouse.bin.SysScanner;
import com.jackwoo.jerrymouse.http.Response;

import java.io.BufferedOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.net.Socket;

/**
 * Author: StupidZhe
 * Date: 2019/12/1
 * Desc:
 **/
public class SysStaticResGenerator {

    public static void send404(Socket client) throws IOException {
        Response response = generate404();
        byte[] res = response.getBytes();
        OutputStream outputStream = client.getOutputStream();
        BufferedOutputStream writer = new BufferedOutputStream(outputStream);
        writer.write(res);
        writer.flush();
        writer.close();
    }

    private static Response generate404() throws IOException {
        File errHtml = SysScanner.scan404();
        String content = FileUtil.getContent(errHtml);
        return Response.generate404(content);
    }
}
